/**
 * Created by dale on 2017/8/2.
 */
var attendDetail;
$(document).ready(function (){
    attendDetail=$('#attendDetail');
    var signStatus=$('#bt_list_signStatus').menubutton({
        iconCls: 'fa  fa-pencil',
        menu: '#mm1',

    });
    var signIn=$('#bt_list_signIn').menubutton({
        iconCls: 'fa  fa-pencil',
        menu: '#mm2',
    });
    var signOut=$('#bt_list_signOut').menubutton({
        iconCls: 'fa  fa-pencil',
        menu: '#mm3',
    });
    var Overtime=$('#bt_list_Overtime').menubutton({
        iconCls: 'fa  fa-pencil',
        menu: '#mm4',

    });
    $('.xh-datagrid-toolbar').parseToolbar();
    $iStaffNumber=addressUri.getParam('iStaffNumber');
    startTime=addressUri.getParam('startTime');
    endTime=addressUri.getParam('endTime');
    attendDetail.initDataGrid(moduleUrl + 'staff/getAttendDetail',{queryParams:{iStaffNumber:$iStaffNumber,endTime:endTime,startTime:startTime}})

    attendDetail.datagrid({
        rowStyler: function(index,row){
            if (row.bColor==1){
                return 'background-color:#CCFFCC;'; // return inline style
            }
        }
    });

    $(signStatus.menubutton('options').menu).menu({  //状态
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var status=0;
            if(item.text=='正常'){
                status=1;
            }else if(item.text=='隔天'){
                status=2;
            }else if(item.text=='请假'){
                status=3;
            }else if(item.text=='调休'){
                status=4;
            }
            var ids = attendDetail.getDataGridSelectedFields('iAttId');
            $.ajax({
                url:moduleUrl+'staff/changeAttend',
                data:{ids:ids,status:status},
                type:'POST',
                success:function (data) {
                    attendDetail.datagrid('reload');
                    // staffList.addDataGridParams({depId:currentDepId}).datagrid('getPanel').panel('setTitle', '职工列表（' + row['sDepName'] + '）');
                },
                error:function (data) {
                    console.log(data);
                }
            });
        }
    });

    $(signIn.menubutton('options').menu).menu({  //上班打卡
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var sin=0;
            if(item.text=='正常'){
                sin=1;
            }else if(item.text=='未打卡'){
                sin=2;
            }else if(item.text=='早退'){
                sin=3;
            }
            var ids = attendDetail.getDataGridSelectedFields('iAttId');
            $.ajax({
                url:moduleUrl+'staff/changeAttend',
                data:{ids:ids,sin:sin},
                type:'POST',
                success:function (data) {
                    // staffList.addDataGridParams({depId:currentDepId}).datagrid('getPanel').panel('setTitle', '职工列表（' + row['sDepName'] + '）');
                    attendDetail.datagrid('reload');
                },
                error:function (data) {
                    console.log(data);
                }
            });
        }
    });

    $(signOut.menubutton('options').menu).menu({  //下班打卡
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var out=0;
            if(item.text=='正常'){
                out=1;
            }else if(item.text=='未打卡'){
                out=2;
            }else if(item.text=='早退'){
                out=3;
            }
            var ids = attendDetail.getDataGridSelectedFields('iAttId');
            $.ajax({
                url:moduleUrl+'staff/changeAttend',
                data:{ids:ids,out:out},
                type:'POST',
                success:function (data) {
                    attendDetail.datagrid('reload');
                    // staffList.addDataGridParams({depId:currentDepId}).datagrid('getPanel').panel('setTitle', '职工列表（' + row['sDepName'] + '）');
                },
                error:function (data) {
                    console.log(data);
                }
            });
        }
    });

    $(Overtime.menubutton('options').menu).menu({  //加班
        onClick: function (item) {
            //item 的相关属性参见API中的menu
            var overtime=0;
            if(item.text=='是'){
                overtime=1;
            }else if(item.text=='否'){
                overtime=0;
            }
            var ids = attendDetail.getDataGridSelectedFields('iAttId');
            $.ajax({
                url:moduleUrl+'staff/changeAttend',
                data:{ids:ids,overtime:overtime},
                type:'POST',
                success:function (data) {
                    attendDetail.datagrid('reload');
                    // staffList.addDataGridParams({depId:currentDepId}).datagrid('getPanel').panel('setTitle', '职工列表（' + row['sDepName'] + '）');
                },
                error:function (data) {
                    console.log(data);
                }
            });
        }
    });




    // xhTool.bindDocKeyDown($('#bt_list_search'));
});